<template>
  <basic-container>
    <avue-crud ref="crud"
               :option="option"
               v-model:page="page"
               :table-loading="loading"
               @on-load="onLoad"
               @refresh-change="refreshChange"
               @search-reset="searchChange"
               @search-change="searchChange"
               v-model="form"
               :data="data">
    </avue-crud>
  </basic-container>
</template>

<script >
import {getLogList} from "/@/api/log";
import {reactive, ref, toRefs} from "vue";
import useCurrentInstance from "/@/utils/useCurrentInstance";
export default {
  name: "log",

  setup(props){
    const { proxy } = useCurrentInstance();

    const option = ref({
      searchMenuSpan: 6,
      tip: false,
      border: true,
      index: false,
      viewBtn: false,
      selection: true,
      addBtn:false,
      searchLabelWidth:100,
      excelBtn:false,
      labelWidth:100,
      menu: false,
      column: [
        {
          label: '编号',
          prop: "id",
        },
        {
          label: '操作用户',
          prop: "realName", search: true,
        },
        {
          label: '操作时间',
          prop: "addTime",
          search: true, searchRange: true, type: 'date',
          format: 'YYYY-MM-DD',
          searchLabelWidth: 120, minWidth: 180,
          valueFormat: 'YYYY-MM-DD',
        },
        {
          label: 'URL',
          prop: "uri",
        },
        {
          prop: "title",
          label: "模块",
        },
        {
          prop: "action",
          label: "操作",
        },
        {
          prop: "message",
          label: "内容",
        },
      ]
    });
    const loading = ref(true);
    const data = ref([]);
    const crud = ref();
    const selectionList = ref([]);
    const queryParams = ref({});
    const form = ref({});
    const page = ref({
      pageSize: 10,
      currentPage: 1,
      total: 0

    })
    const onLoad = (pages, params = {}) => {
      loading.value = true;
      getLogList(Object.assign({ page: pages.currentPage,
        limit: pages.pageSize,},params, queryParams.value)).then(res => {
        const resData =  res.data;
        page.value.total = resData.total;
        data.value = resData.list;
        loading.value = false;
        selectionClear();
      })
    }
    const selectionClear = () => {
      selectionList.value = [];
    }


    const refreshChange = () => {
      onLoad(page.value, queryParams.value);
    }
    const searchChange = (params, done) => {
      if (Array.isArray(params.addTime) && params.addTime.length > 0){
        params.beginTime = params.addTime[0];
        params.endTime = params.addTime[1];
      }
      page.currentPage = 1;
      onLoad(page.value, params);
      done();
    }


    return {
      option,
      loading,
      data,
      page,
      form,
      queryParams,
      onLoad,
      refreshChange,
      searchChange
    }
  }
}
</script>
